package cn.edu.neusoft.demo.hospital2.Controller;

import cn.edu.neusoft.demo.hospital2.Service.MedicalRecordService;
import cn.edu.neusoft.demo.hospital2.pojo.MedicalRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/medicalRecord")
public class MedicalRecordController {

    @Autowired
    private MedicalRecordService medicalRecordService;

    @GetMapping("/all")
    public List<MedicalRecord> getAllRecords() {
        return medicalRecordService.getAllRecords();
    }

    @GetMapping("/{recordId}")
    public MedicalRecord getRecordById(@PathVariable Integer recordId) {
        return medicalRecordService.getRecordById(recordId);
    }

    @PostMapping("/add")
    public int addRecord(@RequestBody MedicalRecord medicalRecord) {
        return medicalRecordService.addRecord(medicalRecord);
    }

    @PutMapping("/update")
    public int updateRecord(@RequestBody MedicalRecord medicalRecord) {
        return medicalRecordService.updateRecord(medicalRecord);
    }

    @DeleteMapping("/delete/{recordId}")
    public int deleteRecordById(@PathVariable Integer recordId) {
        return medicalRecordService.deleteRecordById(recordId);
    }
}
